package vn.demand.dragon.controller
{
	import com.salesbuilder.control.TabManager;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	import vn.demand.dragon.model.ProjectFilesProxy;
	import vn.demand.dragon.model.ProjectItemProxy;
	import vn.demand.dragon.view.ProjectFilesScreenMediator;
	import vn.demand.dragon.view.ProjectFormMediator;
	import vn.demand.dragon.view.ProjectItemScreenMediator;
	import vn.demand.dragon.view.ProjectPanelMediator;
	import vn.demand.dragon.view.TaskScreenMediator;
	import vn.demand.dragon.view.components.ProjectPanel;
	
	public class OpenProjectCommand extends SimpleCommand
	{
		override public function execute( note:INotification ) :void    
		{
			var projectVO:Object = note.getBody();
			RIALogger.debug(this, "" + projectVO);
			if (facade.hasMediator(ProjectPanelMediator.makeId(projectVO))) {
				TabManager.openTab(ProjectPanel, ProjectPanelMediator.makeId(projectVO));
				return;
			}
			var taskMediatorId:String = TaskScreenMediator.makeId(projectVO);
//            facade.registerProxy(new TaskProxy(TaskProxy.makeId(projectVO), projectVO));
//            facade.registerProxy(new QuotationLinesProxy(QuotationLinesProxy.makeId(projectVO), projectVO));
			
			var ui:ProjectPanel = TabManager.openTab(ProjectPanel, ProjectPanelMediator.makeId(projectVO)) as ProjectPanel;
            facade.registerMediator(new ProjectPanelMediator(projectVO, ProjectPanelMediator.makeId(projectVO), ui));
//            facade.registerMediator(new TaskScreenMediator(projectVO, taskMediatorId, ui.taskScreen));
            
//            facade.registerProxy(new TaskProxy(TaskLogScreenMediator.NAME + TaskProxy.makeId(projectVO), projectVO));
//            facade.registerProxy(new TaskLogProxy(TaskLogProxy.makeId(projectVO), projectVO));
            facade.registerProxy(new ProjectItemProxy(ProjectItemProxy.makeId(projectVO), projectVO));
            facade.registerProxy(new ProjectFilesProxy(ProjectFilesProxy.makeId(projectVO), projectVO));
//            facade.registerMediator(new TaskLogScreenMediator(projectVO, TaskLogScreenMediator.makeId(projectVO), ui.taskLogScreen));
            facade.registerMediator(new ProjectItemScreenMediator(projectVO, ProjectItemScreenMediator.makeId(projectVO), ui.projectItemScreen));
            facade.registerMediator(new ProjectFilesScreenMediator(projectVO, ProjectFilesScreenMediator.makeId(projectVO), ui.projectFilesScreen));
            
            facade.registerMediator(new ProjectFormMediator(projectVO, ProjectFormMediator.makeId(projectVO), ui.projectForm));
            
        }

	}
}